<template>
	<view class="info">
		<view class="content">
			<view class="left-block">
				<view class="end-time" v-if="type==1">
					<uni-countdown :show-day="true" :day="timeTwo('day')" color="#fff" splitorColor='#fff'
						:hour="timeTwo('hour')" :minute="timeTwo('minute')" :second="timeTwo('second')" :fontSize='14'
						ref="countDownRef" @timeup='countTwoEnd'></uni-countdown>
				</view>
				<view class="price ">
					<view class="center">
						<span v-if="type==0||type==1">¥</span>
						<span v-if="type==2">积分</span>
						<view class="price-txt" v-if="type==0">
							{{infoData.price/100}}
						</view>
						<view class="price-txt" v-if="type==1">
							{{seckillPrice/100}}
						</view>
						<view class="price-txt" v-if="type==2">
							{{infoData.integral}}
						</view>
						<view class="price-now" v-if="type==0||type==1">
							¥{{infoData.line_price}}
						</view>
					</view>
					 <template v-if="infoData.sales_volume">
						 <view class="count" v-if="type==0||type==1">已售{{infoData.sales_volume}}件</view>
					 </template>
					 <template v-else>
						 <view style="display: flex;">
							 <view class="count" style="margin-right: 24rpx;" v-if="type==0||type==1">库存{{infoData.stock}}件</view>
							 <view class="count" v-if="type==0||type==1">数量{{infoData.count}}件</view>
						 </view>
					 </template>
					<view class="count" v-if="type==2">已兑换{{infoData.sales_volume}}件</view>
				</view>

			</view>
			<button class="right-share" open-type="share" v-if="type==1||type==0">
				<view class="icon center">
					<image :src="share" class="auto-img"></image>
				</view>
				<view class="txt">分享</view>
			</button>
		</view>
		<view class="title">
			{{infoData.title}}
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				share: require('@/static/detail/share.png'),
				seckillPrice: 0,
			}
		},
		props: {
			infoData: {
				type: Object,
				default: {}
			},
			type: {
				type: Number,
				default: 0
			},
			endTime: {
				type: String,
				default: '',
			}
		},
		mounted() {
			this.init()
		},
		computed: {
			timeTwo() {
				return (val) => {

					let str=this.$tools.getUnixToDate('yyyy-mm-dd',this.endTime)
					let strTwo=str .replace(/-/g, "/")
					let times=this.$tools.getDHS(strTwo)
					
					return times[val]
				}
			}
		},
		methods: {
			init() {
				this.seckillPrice = uni.getStorageSync('seckillPrice')
			},
			countTwoEnd() {
				this.$emit('timeEnd')
			},
		}
	}
</script>

<style lang="scss" scoped>
	.info {
		background: #fff;
		padding: 38rpx 44rpx;
		margin-bottom: 24rpx;
	}

	.content {
		display: flex;
		align-items: center;

		.left-block {
			flex: auto;

			.price {
				display: flex;
				align-items: flex-start;
				flex-direction: column;

				span {
					font-size: 24rpx;
					font-weight: 700;
					color: rgba(203, 60, 40, 1);
				}

				.price-txt {
					font-size: 44rpx;
					font-weight: 700;

					color: rgba(203, 60, 40, 1);
				}

				.price-now {
					margin-left: 16rpx;
					font-size: 24rpx;
					font-weight: 400;
					text-decoration-line: line-through;
					color: rgba(102, 102, 102, 1);
				}

				.count {
					margin-top: 28rpx;
					font-size: 24rpx;
					font-weight: 400;
					color: rgba(153, 153, 153, 1);
				}
			}

			.end-time {
				display: inline-block;
				padding: 6rpx 20rpx;
				border-radius: 8rpx;
				background: rgba(203, 60, 40, 1);
			}
		}

		.right-share {
			flex: none;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;

			.icon {
				width: 36rpx;
				height: 36rpx;
			}

			.txt {
				margin-top: 12rpx;
				font-size: 24rpx;
				font-weight: 400;
				color: rgba(0, 0, 0, 1);
			}
		}
	}

	.title {
		margin-top: 24rpx;
		font-size: 32rpx;
		font-weight: 700;
		line-height: 1.5em;
		color: rgba(27, 25, 25, 1)
	}
</style>
